// ****************************************************************************
// @File: ObjectWrapper.h
//
// PURPOSE: The base class for the CSingleObjectWrapper, which defines some common variables
//          and easy to use the abstract way.
// AUTHOR:  Zj Ai
//
// NOTES: 
//     
// HISTORY:
//
//   ------ Zj Ai  05/07/2012 creating the file
//
// @EndHeader@
// ****************************************************************************

#include "stdafx.h"
#include "GlobalDefinition.h"

#pragma once
class CObjectWrapper
{
protected:
	int m_count;	//reference count
	void *m_pRawPointer;	//the real object allocated by usrer;
	DESTORY_PROC m_destoryFun; //a routine to call delete method
	bool m_bInUse; // whether the object is in use
	size_t m_size;	//size of pObj. may not equal sizeof(T)

public:
	CObjectWrapper()
		: m_pRawPointer(NULL), m_destoryFun(NULL), m_bInUse(true), m_size(0)
	{
		m_count = 1;
	}

	int GetRefCount() {return m_count;}
	size_t GetSize() {return m_size; }
	void* GetRawPointer() {return m_pRawPointer;}

	DESTORY_PROC SetFinalizer(DESTORY_PROC finalizer) 
	{
		DESTORY_PROC old = m_destoryFun; 
		m_destoryFun = finalizer;
		return old;
	}

	void SetInUser(bool bInUser) {m_bInUse = bInUser; }
	bool IsInUse() {return m_bInUse; }

	virtual int AddRef() = 0;
	virtual int Release() = 0;

	virtual ~CObjectWrapper(){}
};